{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Robot Return to Origin"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: judgeCircle"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #机器人能否返回原点"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>在二维平面上，有一个机器人从原点 <code>(0, 0)</code> 开始。给出它的移动顺序，判断这个机器人在完成移动后是否在<strong>&nbsp;<code>(0, 0)</code> 处结束</strong>。</p>\n",
    "\n",
    "<p>移动顺序由字符串&nbsp;<code>moves</code>&nbsp;表示。字符 <code>move[i]</code> 表示其第 <code>i</code> 次移动。机器人的有效动作有&nbsp;<code>R</code>（右），<code>L</code>（左），<code>U</code>（上）和 <code>D</code>（下）。</p>\n",
    "\n",
    "<p>如果机器人在完成所有动作后返回原点，则返回 <code>true</code>。否则，返回 <code>false</code>。</p>\n",
    "\n",
    "<p><strong>注意：</strong>机器人“面朝”的方向无关紧要。 <code>“R”</code> 将始终使机器人向右移动一次，<code>“L”</code> 将始终向左移动等。此外，假设每次移动机器人的移动幅度相同。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> moves = \"UD\"\n",
    "<strong>输出:</strong> true\n",
    "<strong>解释：</strong>机器人向上移动一次，然后向下移动一次。所有动作都具有相同的幅度，因此它最终回到它开始的原点。因此，我们返回 true。</pre>\n",
    "\n",
    "<p><strong>示例 2:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> moves = \"LL\"\n",
    "<strong>输出:</strong> false\n",
    "<strong>解释：</strong>机器人向左移动两次。它最终位于原点的左侧，距原点有两次 “移动” 的距离。我们返回 false，因为它在移动结束时没有返回原点。</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示:</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= moves.length &lt;= 2 * 10<sup>4</sup></code></li>\n",
    "\t<li><code>moves</code>&nbsp;只包含字符&nbsp;<code>'U'</code>,&nbsp;<code>'D'</code>,&nbsp;<code>'L'</code>&nbsp;和&nbsp;<code>'R'</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [robot-return-to-origin](https://leetcode.cn/problems/robot-return-to-origin/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [robot-return-to-origin](https://leetcode.cn/problems/robot-return-to-origin/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"UD\"', '\"LL\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        lr=0\n",
    "        ud=0\n",
    "        for i in range(len(moves)):\n",
    "            if moves[i]=='U':\n",
    "                ud+=1\n",
    "            elif moves[i]=='D':\n",
    "                ud-=1\n",
    "            elif moves[i]=='L':\n",
    "                lr+=1\n",
    "            elif moves[i]=='R':\n",
    "                lr-=1\n",
    "        if ud or lr:\n",
    "            return False\n",
    "        else:\n",
    "            return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        l = 0\n",
    "        u = 0\n",
    "        for item in moves:\n",
    "            if item == \"L\":\n",
    "                l += 1\n",
    "            elif item == \"R\":\n",
    "                l -= 1\n",
    "            elif item == \"U\":\n",
    "                u += 1\n",
    "            else:\n",
    "                u -= 1\n",
    "        return l == 0 and u == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        return moves.count('U')==moves.count('D') and moves.count('L')==moves.count('R')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        # x = y = 0\n",
    "        # for i in moves:\n",
    "        #     if i == 'L':\n",
    "        #         x -= 1\n",
    "        #     elif i == 'R':\n",
    "        #         x += 1\n",
    "        #     elif i == \"U\":\n",
    "        #         y += 1\n",
    "        #     else:\n",
    "        #         y -= 1\n",
    "        # return x == y == 0\n",
    "\n",
    "        distance = {\"L\": [-1, 0], \"R\": [1, 0], \"U\": [0, 1], \"D\": [0, -1]}\n",
    "        x = y = 0\n",
    "        for k, v in Counter(moves).items():\n",
    "            x += distance[k][0] * v\n",
    "            y += distance[k][1] * v\n",
    "        return x == y == 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        r_l = 0\n",
    "        d_u = 0\n",
    "        for i in range(len(moves)):\n",
    "            if moves[i] == \"U\":\n",
    "                d_u += 1\n",
    "            elif moves[i] == \"D\":\n",
    "                d_u -= 1\n",
    "            elif moves[i] == \"R\":\n",
    "                r_l += 1\n",
    "            elif moves[i] == \"L\":\n",
    "                r_l -= 1\n",
    "        if r_l == 0 and d_u == 0:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x, y = 0, 0\n",
    "        for t in moves:\n",
    "            if t == 'U':\n",
    "                y += 1\n",
    "            if t == 'D':\n",
    "                y -= 1\n",
    "            if t == 'L':\n",
    "                x -= 1\n",
    "            if t == 'R':\n",
    "                x += 1\n",
    "        return x == 0 and y == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        cot=Counter(moves)\n",
    "        if cot[\"R\"]==cot[\"L\"] and cot[\"U\"]==cot[\"D\"]:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        res = [0, 0]\n",
    "        for i in moves:\n",
    "            if i == 'U':\n",
    "                res[1] += 1\n",
    "            elif i == 'D':\n",
    "                res[1] -= 1\n",
    "            elif i == 'R':\n",
    "                res[0] += 1\n",
    "            else:\n",
    "                res[0] -= 1\n",
    "        return  res[0] == 0 and res[1] == 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        n = len(moves)\n",
    "        move_dic = {'U':1,'D':-1,'L':-1,'R':1}\n",
    "        ud,lr = 0,0\n",
    "        if n%2!=0:\n",
    "            return False\n",
    "        \n",
    "        else:\n",
    "            for i in moves:\n",
    "                if( i == 'U') or (i=='D'):\n",
    "                    ud += move_dic.get(i)\n",
    "                else:\n",
    "                    lr += move_dic.get(i)\n",
    "            if ud==0 and lr==0:\n",
    "                return True\n",
    "            else:\n",
    "                return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        from collections import Counter\n",
    "        a=Counter(moves)\n",
    "        return a.get(\"U\",0)==a.get(\"D\",0) and a.get(\"L\",0)==a.get(\"R\",0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        dic = {'L' : 0, 'R' : 0, 'U': 0, \"D\" : 0}\n",
    "        for i in moves:\n",
    "            dic[i] += 1\n",
    "        return dic['U'] == dic['D'] and dic['L'] == dic['R']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        return moves.count('R') == moves.count('L') and moves.count('U') == moves.count('D')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        return moves.count(\"U\") == moves.count(\"D\") and moves.count(\"L\") == moves.count(\"R\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        from collections import Counter\n",
    "        a = Counter(moves)\n",
    "        return a.get('U',0)==a.get('D',0) and a.get('L',0)==a.get('R',0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        from collections import Counter\n",
    "        a=Counter(moves)\n",
    "        return a.get(\"U\",0)==a.get(\"D\",0) and a.get(\"L\",0)==a.get(\"R\",0)\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        i, j = 0, 0\n",
    "        for x in moves:\n",
    "            if x == \"U\":\n",
    "                i -= 1\n",
    "            elif x == \"D\":\n",
    "                i += 1\n",
    "            elif x == \"R\":\n",
    "                j -= 1\n",
    "            else:\n",
    "                j += 1\n",
    "        return i == j == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def judgeCircle(self, moves):\n",
    "        x = y = 0\n",
    "        for move in moves:\n",
    "            if move == 'U': y -= 1\n",
    "            elif move == 'D': y += 1\n",
    "            elif move == 'L': x -= 1\n",
    "            elif move == 'R': x += 1\n",
    "\n",
    "        return x == y == 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        return moves.count('U') - moves.count('D') == 0 and moves.count('L') - moves.count('R') == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        row = column = 0\n",
    "        for move in moves:\n",
    "            if move == 'U':\n",
    "                row -= 1\n",
    "            elif move == 'D':\n",
    "                row += 1\n",
    "            elif move == 'L':\n",
    "                column -= 1\n",
    "            elif move == 'R':\n",
    "                column += 1\n",
    "        if row == 0 and column == 0:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        idxu=idxd=idxl=idxr=0\n",
    "        if len(moves)<1 or len(moves)>2*10**4:\n",
    "            return False\n",
    "        for i in moves:\n",
    "            if i == \"U\":\n",
    "                idxu += 1\n",
    "            elif i == \"D\":\n",
    "                idxd += 1\n",
    "            elif i == \"L\":\n",
    "                idxl += 1\n",
    "            else :\n",
    "                idxr += 1\n",
    "        if idxu == idxd and idxl == idxr:\n",
    "            return True\n",
    "        else:\n",
    "            return False            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x =0\n",
    "        y =0\n",
    "        for i in moves:\n",
    "            if i == \"R\":\n",
    "                x += 1\n",
    "            elif i== \"L\":\n",
    "                x -= 1\n",
    "            elif i == \"U\":\n",
    "                y -= 1\n",
    "            else:\n",
    "                y += 1\n",
    "        if x==0 and y==0:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        d = [(-1,0),(0,1),(1,0),(0,-1)]\n",
    "        dir = ['U','R','D','L']\n",
    "\n",
    "        ori = [0,0]\n",
    "\n",
    "        for i in range(len(moves)):\n",
    "            for j in range(4):\n",
    "                if moves[i] == dir[j]:\n",
    "                    ori[0] = ori[0] + d[j][0]\n",
    "                    ori[1] = ori[1] + d[j][1]\n",
    "        \n",
    "        if ori == [0,0]:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def judgeCircle(self, moves: str) -> bool:\r\n",
    "        up=left=0\r\n",
    "        for d in moves:\r\n",
    "            if d=='U':\r\n",
    "                up+=1\r\n",
    "            elif d=='D':\r\n",
    "                up-=1\r\n",
    "            elif d=='L':\r\n",
    "                left+=1\r\n",
    "            else:\r\n",
    "                left-=1\r\n",
    "        return up==left==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x = y = 0\n",
    "        for i in moves:\n",
    "            if i == 'L':\n",
    "                x -= 1\n",
    "            elif i == 'R':\n",
    "                x += 1\n",
    "            elif i == \"U\":\n",
    "                y += 1\n",
    "            else:\n",
    "                y -= 1\n",
    "        return x == y == 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# run in Leetcode 657\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x = 0\n",
    "        y = 0\n",
    "        for move in range(len(moves)):\n",
    "            if moves[move] == \"U\":\n",
    "                y += 1\n",
    "            if moves[move] == \"D\":\n",
    "                y -= 1\n",
    "            if moves[move] == \"L\":\n",
    "                x -= 1\n",
    "            if moves[move] == \"R\":\n",
    "                x += 1\n",
    "        if x == 0 and y == 0:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x,y=0,0\n",
    "        for i in moves:\n",
    "            if i==\"U\":\n",
    "                y+=1\n",
    "            elif i ==\"D\":\n",
    "                y-=1\n",
    "            elif i ==\"R\":\n",
    "                x+=1\n",
    "            else:\n",
    "                x-=1\n",
    "        return x==y==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x = y = 0\n",
    "        for move in moves:\n",
    "            if move == 'U': y -= 1\n",
    "            elif move == 'D': y += 1\n",
    "            elif move == 'L': x -= 1\n",
    "            elif move == 'R': x += 1\n",
    "\n",
    "        return x == y == 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        a=0\n",
    "        b=0\n",
    "        c=0\n",
    "        d=0\n",
    "        for i in moves:\n",
    "            if i=='U':\n",
    "                a+=1\n",
    "            elif i=='D':\n",
    "                b+=1\n",
    "            elif i=='R':\n",
    "                c+=1\n",
    "            else:\n",
    "                d+=1\n",
    "        if a==b and c==d:\n",
    "            return(True)\n",
    "        else:\n",
    "            return(False)  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        c=Counter(moves)\n",
    "        return c['U']==c['D'] and c['L']==c['R']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        ans=[0,0]\n",
    "        move={'U':1,'D':-1,'R':1,'L':-1}\n",
    "        for i in moves:\n",
    "            if i in 'UD':\n",
    "                ans[0]+=move[i]\n",
    "            else:\n",
    "                ans[1]+=move[i]\n",
    "        return ans==[0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        record=[0,0]\n",
    "        for i in range(len(moves)):\n",
    "            if moves[i]=='U':\n",
    "                record[0]=record[0]+1\n",
    "            elif moves[i]=='D':\n",
    "                record[0]= record[0]-1\n",
    "            elif moves[i]=='L':\n",
    "                record[1]=record[1]-1\n",
    "            elif moves[i]=='R':\n",
    "                record[1]=record[1]+1\n",
    "        return record[0]==0 and record[1]==0\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        hmap = dict()\n",
    "        hmap['R'] = [0, 1]\n",
    "        hmap['L'] = [0, -1]\n",
    "        hmap['U'] = [-1, 0]\n",
    "        hmap['D'] = [1, 0]\n",
    "\n",
    "        pos = [0, 0]\n",
    "        for c in moves:\n",
    "            dx,dy = hmap[c]\n",
    "            pos[0] += dx\n",
    "            pos[1] += dy\n",
    "        \n",
    "        return pos == [0, 0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        step = defaultdict(int)\n",
    "\n",
    "        for move in moves:\n",
    "            step[move] += 1\n",
    "        \n",
    "        if step['U'] != step['D']:\n",
    "            return False\n",
    "        if step['R'] != step['L']:\n",
    "            return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        moves=Counter(moves)\n",
    "        if 'U' not in moves:\n",
    "            moves['U']=0\n",
    "        if 'D' not in moves:\n",
    "            moves['D']=0\n",
    "        if 'L' not in moves:\n",
    "            moves['L']=0\n",
    "        if 'R' not in moves:\n",
    "            moves['R']=0\n",
    "        return moves['U']==moves['D'] and moves['L']==moves['R']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x=0\n",
    "        y=0\n",
    "        for m in moves:\n",
    "            if m=='U':\n",
    "                y+=1\n",
    "            elif m=='D':\n",
    "                y-=1\n",
    "            elif m=='L':\n",
    "                x-=1\n",
    "            elif m=='R':\n",
    "                x+=1\n",
    "        return x==0 and y==0\n",
    "        \n",
    "        moves=Counter(moves)\n",
    "        if 'U' not in moves:\n",
    "            moves['U']=0\n",
    "        if 'D' not in moves:\n",
    "            moves['D']=0\n",
    "        if 'L' not in moves:\n",
    "            moves['L']=0\n",
    "        if 'R' not in moves:\n",
    "            moves['R']=0\n",
    "        return moves['U']==moves['D'] and moves['L']==moves['R']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        countl = 0\n",
    "        countd = 0\n",
    "        for i in moves:\n",
    "            if i == \"R\":\n",
    "                countl -= 1\n",
    "            elif i == \"L\":\n",
    "                countl += 1\n",
    "            elif i == \"U\":\n",
    "                countd -= 1\n",
    "            else:\n",
    "                countd += 1\n",
    "        if countd == countl == 0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        m_list=collections.Counter(moves)\n",
    "        return True if m_list['R']==m_list['L'] and m_list['U']==m_list['D'] else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x,y=0,0\n",
    "        for i in moves:\n",
    "            if i=='R':\n",
    "                x+=1\n",
    "            elif i=='L':\n",
    "                x-=1\n",
    "            elif i=='U':\n",
    "                y+=1\n",
    "            else:\n",
    "                y-=1\n",
    "        return x==0 and y==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        if len(moves)%2:\n",
    "            return False\n",
    "        ans=[0,0]\n",
    "        move={'U':1,'D':-1,'R':1,'L':-1}\n",
    "        for i in moves:\n",
    "            if i in 'UD':\n",
    "                ans[0]+=move[i]\n",
    "            else:\n",
    "                ans[1]+=move[i]\n",
    "        return ans==[0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        n=len(moves)\n",
    "        right,left,up,down=0,0,0,0\n",
    "        for i in range(n):\n",
    "            if moves[i]=='R':\n",
    "                right+=1\n",
    "            elif moves[i]=='L':\n",
    "                left+=1\n",
    "            elif moves[i]=='U':\n",
    "                up+=1\n",
    "            else:\n",
    "                down+=1\n",
    "        if right==left and up==down:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        vertical,level=0,0\n",
    "        for c in moves:\n",
    "            if c=='U':\n",
    "                vertical+=1\n",
    "            elif c=='D':\n",
    "                vertical-=1\n",
    "            elif c=='L':\n",
    "                level-=1\n",
    "            else:\n",
    "                level+=1\n",
    "        return vertical==0 and level==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        if len(moves)%2:\n",
    "            return False\n",
    "        ans=[0,0]\n",
    "        move={'U':1,'D':-1,'R':1,'L':-1}\n",
    "        for i in moves:\n",
    "            if i in 'UD':\n",
    "                ans[0]+=move[i]\n",
    "            else:\n",
    "                ans[1]+=move[i]\n",
    "        return ans==[0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        cnt = Counter(moves)\n",
    "        return cnt['U']==cnt['D'] and cnt['L']==cnt['R']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        lst=[0,0]\n",
    "        for i in moves:\n",
    "            if i == 'R':\n",
    "                lst[0]=lst[0]+1\n",
    "            if i == 'L':\n",
    "                lst[0]=lst[0]-1\n",
    "            if i == 'U':\n",
    "                lst[1]=lst[1]+1\n",
    "            if i == 'D':\n",
    "                lst[1]=lst[1]-1\n",
    "        if lst==[0,0]:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def judgeCircle(self, moves: str) -> bool:\r\n",
    "        cnt = Counter(moves)\r\n",
    "        return cnt[\"U\"] == cnt[\"D\"] and cnt[\"L\"] == cnt[\"R\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x=y=0\n",
    "        for move in moves:\n",
    "            match move:\n",
    "                case 'U':y-=1\n",
    "                case 'D':y+=1\n",
    "                case 'L':x-=1\n",
    "                case 'R':x+=1\n",
    "        return x==y==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        path = {\n",
    "            'U': 0,\n",
    "            'D': 0,\n",
    "            'L': 0,\n",
    "            'R': 0\n",
    "        }\n",
    "        for m in moves:\n",
    "            path[m] += 1\n",
    "        \n",
    "        return path['U'] == path['D'] and path['L'] == path['R']\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        a,b=0,0\n",
    "\n",
    "        for s in moves:\n",
    "            if s==\"R\":\n",
    "                a+=1\n",
    "            elif s==\"L\":\n",
    "                a-=1\n",
    "            elif s==\"U\":\n",
    "                b+=1\n",
    "            else:\n",
    "                b-=1\n",
    "\n",
    "        return a==0 and b==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        curr = [0, 0]\n",
    "        for itm in moves:\n",
    "            if itm == 'U':\n",
    "                curr[1] += 1\n",
    "            if itm == 'D':\n",
    "                curr[1] -= 1\n",
    "            if itm == 'L':\n",
    "                curr[0] -= 1\n",
    "            if itm == 'R':\n",
    "                curr[0] += 1\n",
    "        return curr == [0, 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        l, u = 0, 0\n",
    "        for m in moves:\n",
    "            if m == 'L':\n",
    "                l += 1\n",
    "            elif m == 'R':\n",
    "                l -= 1\n",
    "            elif m == 'U':\n",
    "                u += 1\n",
    "            else:\n",
    "                u -= 1\n",
    "        \n",
    "        return l == 0 and u == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x, y = 0, 0\n",
    "        for move in moves:\n",
    "            if move == 'R':\n",
    "                x += 1\n",
    "            elif move == 'L':\n",
    "                x -= 1\n",
    "            elif move == 'U':\n",
    "                y += 1\n",
    "            else:\n",
    "                y -= 1\n",
    "        \n",
    "        return x == 0 and y == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        if len(moves) == 1:\n",
    "            return False\n",
    "        res=[0,0]\n",
    "\n",
    "        for i in moves:\n",
    "            if i == 'U':\n",
    "                res[0] += 1\n",
    "            elif i == 'D':\n",
    "                res[0] -= 1\n",
    "            elif i == 'L':\n",
    "                res[1] += 1\n",
    "            else:\n",
    "                res[1] -= 1\n",
    "        if res==[0,0]:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        ud = 0\n",
    "        lr = 0\n",
    "        for i in moves:\n",
    "            if i == \"U\":\n",
    "                ud +=1\n",
    "            elif i == \"D\":\n",
    "                ud -=1\n",
    "            elif i == \"L\":\n",
    "                lr += 1\n",
    "            elif i == \"R\":\n",
    "                lr -= 1\n",
    "        if ud ==0 and lr == 0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        v = h = 0\n",
    "        for c in moves:\n",
    "            match c:\n",
    "                case 'R': v += 1\n",
    "                case 'L': v -= 1\n",
    "                case 'U': h += 1\n",
    "                case 'D': h -= 1\n",
    "        return h == v == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        hmap = Counter(moves)\n",
    "        return hmap['D'] == hmap['U'] and hmap['L'] == hmap['R']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        # i,j 为机器人的坐标\n",
    "        i = j = 0\n",
    "        dic = {\n",
    "            'U':(-1,0),\n",
    "            'D':(1,0),\n",
    "            'L':(0,-1),\n",
    "            'R':(0,1),\n",
    "        }\n",
    "        for step in moves:\n",
    "            row,col = dic[step]\n",
    "            i += row\n",
    "            j += col\n",
    "        return i==0 and j==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x=y=0\n",
    "        for move in moves:\n",
    "            if move=='U':y+=1\n",
    "            elif move=='D':y-=1\n",
    "            elif move=='L':x-=1\n",
    "            elif move=='R':x+=1\n",
    "        return x==y==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        d={'R':0,'L':0,'U':0,'D':0}\n",
    "        for i in moves:\n",
    "            if i=='R' or i=='U':\n",
    "                d[i]=d[i]+1\n",
    "            else:\n",
    "                d[i]=d[i]-1\n",
    "        #print(d)\n",
    "        if d['R']+d['L']==0:\n",
    "            if d['U']+d['D']==0:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        return moves.count('U')==moves.count('D') and moves.count('L')==moves.count('R')\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x = y =0\n",
    "        for i in moves:\n",
    "            if i == \"L\":\n",
    "                x -= 1\n",
    "            elif i == \"R\":\n",
    "                x += 1\n",
    "            elif i == \"U\":\n",
    "                y += 1\n",
    "            else:\n",
    "                y -= 1\n",
    "        return x == y == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        if moves.count('U')==moves.count('D') and moves.count('R')==moves.count('L'):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        x = y =0\n",
    "        dx = {\"R\":1,\"L\":-1,\"U\":0,\"D\":0}\n",
    "        dy = {\"R\":0,\"L\":0,\"U\":1,\"D\":-1}\n",
    "        for i in moves:\n",
    "            x += dx[i]\n",
    "            y += dy[i]\n",
    "        return x == y == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        dic={'R':(1,0),'L':(-1,0),'U':(0,1),'D':(0,-1)}\n",
    "        a=0\n",
    "        b=0\n",
    "        for i in moves:\n",
    "            a+=dic[i][0]\n",
    "            b+=dic[i][1]\n",
    "        if a==0 and b==0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def judgeCircle(self, moves: str) -> bool:\r\n",
    "        dic = defaultdict(int)\r\n",
    "        for c in moves:\r\n",
    "            dic[c] += 1\r\n",
    "        if dic['U'] == dic['D'] and dic['L'] == dic['R']:\r\n",
    "            return True\r\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        m = Counter(moves)\n",
    "        if m['U'] == m['D'] and m['L'] == m['R']:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        cnt = Counter(moves)\n",
    "        return cnt[\"U\"] == cnt[\"D\"] and cnt[\"L\"] == cnt[\"R\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        return Counter(moves)['R']==Counter(moves)['L'] and Counter(moves)['U']==Counter(moves)['D']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, m: str) -> bool:\n",
    "        cx,cy=0,0\n",
    "        for i in m:\n",
    "            if i==\"R\":\n",
    "                cx+=1\n",
    "            if i==\"L\":\n",
    "                cx-=1\n",
    "            if i==\"U\":\n",
    "                cy+=1\n",
    "            if i==\"D\":\n",
    "                cy-=1\n",
    "        return cx==0 and cy==0\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        # 按题目要求进行模拟\n",
    "        x = 0\n",
    "        y = 0\n",
    "        for i in range(len(moves)):\n",
    "            if (moves[i] == 'U'):\n",
    "                y += 1\n",
    "            if (moves[i] == 'D'):\n",
    "                y -= 1\n",
    "            if (moves[i] == 'L'):\n",
    "                x += 1\n",
    "            if (moves[i] == 'R'):\n",
    "                x -= 1\n",
    "        return x == 0 and y == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        a = {'D':0,'U':0,'R':0,'L':0}\n",
    "        for c in moves:\n",
    "            a[c] += 1\n",
    "        if a['D'] == a['U'] and a['L'] == a['R']:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        position = [0, 0]\n",
    "        for move in moves:\n",
    "            if move == 'R':\n",
    "                position[0] += 1\n",
    "            elif move == 'L':\n",
    "                position[0] -= 1\n",
    "            elif move == 'U':\n",
    "                position[1] += 1\n",
    "            else:\n",
    "                position[1] -= 1\n",
    "        return position == [0, 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self):\n",
    "        self.dict = {'R':[1,0],'L':[-1,0],'U':[0,1],'D':[0,-1]}\n",
    "\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        coordinate = [0,0]\n",
    "        for i in moves:\n",
    "            coordinate[0] += self.dict[i][0]\n",
    "            coordinate[1] += self.dict[i][1]\n",
    "        return coordinate == [0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        X = 0\n",
    "        Y = 0\n",
    "        for i in range(len(moves)):\n",
    "            if moves[i] == \"U\":\n",
    "                Y += 1\n",
    "            if moves[i] == \"D\":\n",
    "                Y -= 1\n",
    "            if moves[i] == \"L\":\n",
    "                X += 1\n",
    "            if moves[i] == \"R\":\n",
    "                X -= 1\n",
    "        if (X == 0) & (Y == 0):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def judgeCircle(self, moves: str) -> bool:\n",
    "        place = [0,0]\n",
    "        for i in moves:\n",
    "            if i == 'R':\n",
    "                place[0] += 1\n",
    "            elif i == 'L':\n",
    "                place[0] -= 1\n",
    "            elif i == 'U':\n",
    "                place[1] += 1\n",
    "            else:\n",
    "                place[1] -= 1\n",
    "        if place[0] == 0 and place[1] == 0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
